package com.qiguliuxing.dts.admin.web;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.qiguliuxing.dts.admin.annotation.RequiresPermissionsDesc;
import com.qiguliuxing.dts.admin.dao.*;
import com.qiguliuxing.dts.admin.dao.dto.IorderStockPageQuery;
import com.qiguliuxing.dts.admin.service.AdminIorderService;
import com.qiguliuxing.dts.admin.service.AdminIorderStockService;
import com.qiguliuxing.dts.admin.util.AuthSupport;
import com.qiguliuxing.dts.core.util.ResponseUtil;
import com.qiguliuxing.dts.core.validator.Order;
import com.qiguliuxing.dts.core.validator.Sort;
import com.qiguliuxing.dts.db.domain.GmInstrument;
import com.qiguliuxing.dts.db.domain.IoralStock;

import com.qiguliuxing.dts.db.domain.ProductProduction;
import com.qiguliuxing.dts.db.service.IoralStockService;
import com.qiguliuxing.dts.db.service.ProductProductionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotNull;
import java.sql.Date;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/admin/iorderStock")
@Validated
public class AdminIorderStockController {

    @Autowired
    private AdminIorderStockService adminIorderStockService;
    @Autowired
    private IoralStockService ioralStockService;
    @Autowired
    private ProductProductionService productProductionService;

    private static final Logger logger = LoggerFactory.getLogger(AdminIorderStockController.class);

    @RequiresPermissions("admin:iorderStock:list")
    @RequiresPermissionsDesc(menu = { "碘131生产发货管理", "备货管理" }, button = "查询")
    @PostMapping("/list")
    public Object list(@RequestBody IorderStockPageQuery iorderStockPageQuery /*@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "15") Integer limit,
                       String batchNumber,
                       String sort,
                       @Order @RequestParam(defaultValue = "desc") String order*/) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 碘131生产发货管理->查询,请求参数:instrumentNumber:{},instrumentName:{},page:{}",iorderStockPageQuery);
        //需要区分数据权限，如果属于品牌商管理员，则需要获取当前用户管理品牌店铺
        List<IoralStock> ioralStockList = ioralStockService.querySelective(iorderStockPageQuery.getPage(),iorderStockPageQuery.getLimit(),iorderStockPageQuery.getBatchNumber(),"build_time",iorderStockPageQuery.getOrder());
        long total = PageInfo.of(ioralStockList).getTotal();
        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", ioralStockList);
        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));
        return ResponseUtil.ok(data);

       /* return adminIorderStockService.list(currentPage,pagesize,batchNumber,page, limit, sort,order);*/
    }

    @GetMapping("/listSelectBatchNumber")
    public Object listSelectBatchNumber(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "15") Integer limit,
                       @RequestParam(value = "batchNumber")String batchNumber,
                       String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 碘131生产发货管理->查询,请求参数:instrumentNumber:{},instrumentName:{},page:{}",order);
        //需要区分数据权限，如果属于品牌商管理员，则需要获取当前用户管理品牌店铺
        List<IoralStock> ioralStockList = ioralStockService.querySelective(page,limit,batchNumber,sort,order);
        long total = PageInfo.of(ioralStockList).getTotal();
        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", ioralStockList);
        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));
        return ResponseUtil.ok(data);

        /* return adminIorderStockService.list(currentPage,pagesize,batchNumber,page, limit, sort,order);*/
    }

    /*@RequiresPermissions("admin:iorderStock:list2")*/
    /*@RequiresPermissionsDesc(menu = { "碘131生产发货管理", "备货管理" }, button = "查询")*/
    @PostMapping("/list2")
    public Object list2(@RequestBody IorderStockPageQuery iorderStockPageQuery /*@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "15") Integer limit,
                       String batchNumber,
                       String sort,
                       @Order @RequestParam(defaultValue = "desc") String order*/) {
        logger.info(iorderStockPageQuery.getBatchNumber());
        logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 碘131生产发货管理->查询,请求参数:instrumentNumber:{},instrumentName:{},page:{}", iorderStockPageQuery);
        //需要区分数据权限，如果属于品牌商管理员，则需要获取当前用户管理品牌店铺
        List<IoralStock> ioralStockList = ioralStockService.querySelective(iorderStockPageQuery.getPage(),iorderStockPageQuery.getLimit(),iorderStockPageQuery.getBatchNumber(),iorderStockPageQuery.getSort(),iorderStockPageQuery.getOrder());

        long total = PageInfo.of(ioralStockList).getTotal();
        String batchN="";
        Integer id=0;
        String volume="";
        String Count="";
        String useTime="";
        Integer pieces=0;
        List<String> stocks2=new ArrayList<>();
        Object stocks3=null;


        if(ioralStockList!=null){

            for(IoralStock ioralStock:ioralStockList){
                /*logger.info("吵你妈");*/
                logger.info(String.valueOf(ioralStock.getEditPieces()));
                ioralStock.setEditPieces(ioralStock.getPieces());
                ioralStockService.updateById(ioralStock);
                logger.info(String.valueOf(ioralStock.getEditPieces()));
                batchN=ioralStock.getBatchNumber();
                volume=ioralStock.getVolume();
                id=ioralStock.getId();
                Count=ioralStock.getOrderCount().toString();
                useTime=ioralStock.getUseTime().toString().substring(0,10);
                pieces=ioralStock.getEditPieces();
                String stockAll=batchN+"/分装体积："+volume+"ml/件数："+pieces+"/订量："+Count+"mCi/使用时间："+useTime+"/id："+id;
                stocks2.add(stockAll);
            }

        }
       stocks3=stocks2.stream()
               .collect(Collectors.groupingBy(s -> s.substring(0, 10)))
               .entrySet()
               .stream()
               .map(entry -> {
                   List<Map<String, String>> options = entry.getValue().stream()
                           .map(option -> {
                               Map<String, String> optionMap = new HashMap<>();
                               optionMap.put("value", option);
                               optionMap.put("label", option.substring(0,10));
                               return optionMap;
                           })
                           .collect(Collectors.toList());
//                   Map.of(
//                           "label", "产品批号:"+entry.getKey().substring(0,10),
//                           "options", entry.getValue().stream().map(option -> Map.of("value", option, "label", option.substring(11))).collect(Collectors.toList())
//                   );
                   return options; //group;
               })
               .collect(Collectors.toList());
        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", stocks3);
        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(stocks2));
        return ResponseUtil.ok(data);

        /* return adminIorderStockService.list(currentPage,pagesize,batchNumber,page, limit, sort,order);*/
    }
    @GetMapping("/list12")
    public Object list12(@RequestParam(defaultValue = "1") Integer page,
                        @RequestParam(defaultValue = "15") Integer limit,
                        @RequestParam Integer  currentPage,
                        @RequestParam Integer pagesize,
                        String batchNumber,
                        String sort,
                        @Order @RequestParam(defaultValue = "desc") String order) {
        logger.info(batchNumber);
        logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 碘131生产发货管理->查询,请求参数:instrumentNumber:{},instrumentName:{},page:{}", currentPage);
        //需要区分数据权限，如果属于品牌商管理员，则需要获取当前用户管理品牌店铺
        List<IoralStock> ioralStockList = ioralStockService.querySelective(page,limit,batchNumber,sort,order);

        long total = PageInfo.of(ioralStockList).getTotal();
        String batchN="";
        Integer id=0;
        String volume="";
        String Count="";
        String useTime="";
        Integer pieces=0;
        List<IoralStock> stocks2=new ArrayList<>();
        Object stocks3=null;


        if(ioralStockList!=null){

            for(IoralStock ioralStock:ioralStockList){
                /*logger.info("吵你妈");*/
                batchN=ioralStock.getBatchNumber();
                volume=ioralStock.getVolume();
                id=ioralStock.getId();
                Count=ioralStock.getOrderCount().toString();
                useTime=ioralStock.getUseTime().toString().substring(0,10);
                pieces=ioralStock.getPieces();
                String stockAll=batchN+"/分装体积："+volume+"/我是换过来的哈哈哈哈哈哈哈哈件数："+pieces+"/订量："+Count+"/使用时间："+useTime+"/id："+id;
                stocks2.add(ioralStock);
            }

        }
        stocks3=stocks2.stream()
                .collect(Collectors.groupingBy(s -> s.getBatchNumber()))
                .entrySet()
                .stream()
                .map(entry -> {
//                    Map<String, Object> group = Map.of(
//                            "label", "产品批号:"+entry.getKey(),
//                            "options", entry.getValue().stream().map(option -> Map.of("value", option, "label", option)).collect(Collectors.toList())
//                    );
                    return null; //group;
                })
                .collect(Collectors.toList());
        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", stocks3);
        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(stocks2));
        return ResponseUtil.ok(data);

        /* return adminIorderStockService.list(currentPage,pagesize,batchNumber,page, limit, sort,order);*/
    }


    @PostMapping("/list3")
    public Object getSubCategories(@RequestParam("id") Integer id,
                                   @RequestParam("selectedItem") String selectedItem) {
        /*List<IoralStock> ioralStockList = ioralStockService.queryByBatchNumber(batchNumber);*/
        Map<String, Object> data = new HashMap<>();
       logger.info(selectedItem);
        data.put("items", "传过去了");
        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));
        return ResponseUtil.ok(data);
    }

    @GetMapping("/editStock")
    public Object editStocks(@RequestParam("id") Integer id,
                                   @RequestParam("pieces") Integer pieces) {
        /*List<IoralStock> ioralStockList = ioralStockService.queryByBatchNumber(batchNumber);*/
        Map<String, Object> data = new HashMap<>();
        IoralStock ioralStock=ioralStockService.findById(id);
        String stockAll="";
        Integer actPiece=0;
        actPiece=ioralStock.getEditPieces();
        Object list2=getStockAll(id,pieces);

        logger.info(String.valueOf(pieces));
        data.put("items", list2);
        data.put("actPiece",actPiece);
        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));
        return ResponseUtil.ok(data);
    }
    @GetMapping("/getBachNumber")
    public Object getBachNumbers() {
        /*List<IoralStock> ioralStockList = ioralStockService.queryByBatchNumber(batchNumber);*/
        Map<String, Object> data = new HashMap<>();
        List<IoralStock> listStock=ioralStockService.querySelective(1,20,"","volume","desc");
        List<String> batchNumbers=new ArrayList<>();
        for(IoralStock ioralStock:listStock){
            if(!batchNumbers.contains(ioralStock.getBatchNumber())){
                batchNumbers.add(ioralStock.getBatchNumber());
            }
        }

        data.put("items", batchNumbers);

        logger.info("【请求结束】备货管理->查看备货->查询,响应结果:{}", JSONObject.toJSONString(data));
        return ResponseUtil.ok(data);
    }



    @GetMapping("/rollbackStock")
    public Object rollbackStock(@RequestParam("id") Integer id,
                             @RequestParam("pieces") Integer pieces) {
        /*List<IoralStock> ioralStockList = ioralStockService.queryByBatchNumber(batchNumber);*/
        Map<String, Object> data = new HashMap<>();
        /*IoralStock ioralStock=ioralStockService.findById(id);*/
        String stockAll="";
        Integer actPiece=0;
        /*actPiece=ioralStock.getEditPieces();*/
        Object list2=rollbackStocks(id,pieces);

        logger.info(String.valueOf(pieces));
        data.put("items", list2);
        /*data.put("actPiece",actPiece);*/
        logger.info("【请求结束】碘订单管理->仪器列表->查询,响应结果:{}", JSONObject.toJSONString(data));
        return ResponseUtil.ok(data);
    }

    public Object getStockAll(Integer id,Integer piece){
        String batchNumber="";
        Integer page=1;
        Integer limit=30;
        String sort="";
        String order="desc";
        List<IoralStock> ioralStockList = ioralStockService.querySelective(page,limit,batchNumber,sort,order);

       /* long total = PageInfo.of(ioralStockList).getTotal();*/
        String batchN="";
        String volume="";
        String Count="";
        String useTime="";
        Integer pieces2=0;
        List<String> stocks2=new ArrayList<>();
        Object stocks3=null;


        if(ioralStockList!=null){

            for(IoralStock ioralStock:ioralStockList){

               if(ioralStock.getEditPieces()>0) {
                   logger.info(String.valueOf(ioralStock.getEditPieces()));
                   batchN = ioralStock.getBatchNumber();
                   volume = ioralStock.getVolume();
                   Count = ioralStock.getOrderCount().toString();
                   useTime = ioralStock.getUseTime().toString().substring(0, 10);
                   if (ioralStock.getId() == id) {
                       if (ioralStock.getEditPieces() > piece) {

                           ioralStock.setEditPieces(ioralStock.getEditPieces() - piece);
                           ioralStockService.updateById(ioralStock);
                           pieces2 = ioralStock.getEditPieces();
                           String stockAll = batchN + "/分装体积：" + volume + "ml/件数：" + pieces2 + "/订量：" + Count + "mCi/使用时间：" + useTime + "/id：" + ioralStock.getId();
                           stocks2.add(stockAll);

                       } else if (ioralStock.getEditPieces() == piece) {
                           ioralStock.setEditPieces(0);
                           ioralStockService.updateById(ioralStock);

                       } else {

                       }

                   }else{
                       pieces2 = ioralStock.getEditPieces();
                       String stockAll = batchN + "/分装体积：" + volume + "ml/件数：" + pieces2 + "/订量：" + Count + "mCi/使用时间：" + useTime + "/id：" + ioralStock.getId();
                       stocks2.add(stockAll);
                   }

               }
            }

        }
        stocks3=stocks2.stream()
                .collect(Collectors.groupingBy(s -> s.substring(0, 10)))
                .entrySet()
                .stream()
                .map(entry -> {
                    List<Map<String, String>> options = entry.getValue().stream()
                            .map(option -> {
                                Map<String, String> optionMap = new HashMap<>();
                                optionMap.put("value", option);
                                optionMap.put("label", option.substring(0,10));
                                return optionMap;
                            })
                            .collect(Collectors.toList());
//                   Map.of(
//                           "label", "产品批号:"+entry.getKey().substring(0,10),
//                           "options", entry.getValue().stream().map(option -> Map.of("value", option, "label", option.substring(11))).collect(Collectors.toList())
//                   );
                    return options; //group;
                })
                .collect(Collectors.toList());
        return stocks3;
    }

    public Object rollbackStocks(Integer id,Integer piece){
        String batchNumber="";
        Integer page=1;
        Integer limit=30;
        String sort="";
        String order="desc";
        List<IoralStock> ioralStockList = ioralStockService.querySelective(page,limit,batchNumber,sort,order);

        /* long total = PageInfo.of(ioralStockList).getTotal();*/
        String batchN="";
        String volume="";
        String Count="";
        String useTime="";
        Integer pieces2=0;
        List<String> stocks2=new ArrayList<>();
        Object stocks3=null;
        if(ioralStockList!=null){
            for(IoralStock ioralStock:ioralStockList){
                if(ioralStock.getId()==id){
                    ioralStock.setEditPieces(ioralStock.getEditPieces()+piece);
                    ioralStockService.updateById(ioralStock);
                }
            }
        }

        if(ioralStockList!=null){

            for(IoralStock ioralStock:ioralStockList){
                /*logger.info("吵你妈");*/
                if(ioralStock.getEditPieces()>0) {
                    logger.info(String.valueOf(ioralStock.getEditPieces()));
                    batchN = ioralStock.getBatchNumber();
                    volume = ioralStock.getVolume();
                    Count = ioralStock.getOrderCount().toString();
                    useTime = ioralStock.getUseTime().toString().substring(0, 10);

                        pieces2 = ioralStock.getEditPieces();
                        String stockAll = batchN + "/分装体积：" + volume + "ml/件数：" + pieces2 + "/订量：" + Count + "mCi/使用时间：" + useTime + "/id：" + ioralStock.getId();
                        stocks2.add(stockAll);

                }
            }

        }
        stocks3=stocks2.stream()
                .collect(Collectors.groupingBy(s -> s.substring(0, 10)))
                .entrySet()
                .stream()
                .map(entry -> {
                    List<Map<String, String>> options = entry.getValue().stream()
                            .map(option -> {
                                Map<String, String> optionMap = new HashMap<>();
                                optionMap.put("value", option);
                                optionMap.put("label", option.substring(0,10));
                                return optionMap;
                            })
                            .collect(Collectors.toList());
//                   Map.of(
//                           "label", "产品批号:"+entry.getKey().substring(0,10),
//                           "options", entry.getValue().stream().map(option -> Map.of("value", option, "label", option.substring(11))).collect(Collectors.toList())
//                   );
                    return options; //group;
                })
                .collect(Collectors.toList());
        return stocks3;
    }


    @RequiresPermissions("admin:iorders:list")
    @GetMapping("/categories")
    public ResponseEntity<List<IoralStock>> getCategories() {
        List<IoralStock> iorderStockList = ioralStockService.queryByNew(1,4);
        return ResponseEntity.ok(iorderStockList);
    }

/*    @GetMapping("/catAndBrand")
    public Object catAndBrand() {
        return adminInstrumentService.catAndBrand();
    }*/

    /**
     * 编辑商品
     *
     * @param iorderStockAll
     * @return
     */
    @RequiresPermissions("admin:iorderStock:update")
    @RequiresPermissionsDesc(menu = { "碘131生产发货管理", "备货管理" }, button = "编辑")
    @PostMapping("/update")
    public Object update(@RequestBody IorderStockAll iorderStockAll) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 碘131生产发货管理->生产列表->编辑,请求参数:{}", JSONObject.toJSONString(iorderStockAll));

        return adminIorderStockService.update(iorderStockAll);
    }





    /**
     * 添加商品
     *哈哈哈哈哈哈哈哈哈
     * @return
     */

    @GetMapping("/publishiorderStock")
    public Object create(@RequestParam String batchNumber,@RequestParam String orderCount,@RequestParam String useTime,@RequestParam Integer piece,@RequestParam Double splitQuantity,@RequestParam String activity,@RequestParam String deliveryType) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName() + "] 碘131生产发货管理->订单列表->新增,请求参数:{}", JSONObject.toJSONString(orderCount));
        logger.info(batchNumber+" "+useTime+" "+orderCount+" "+piece);
        IoralStock ioralStock = new IoralStock();
        String dateTimeString = useTime.substring(0,10)+" 12:00:00";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, formatter);
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        ProductProduction production=productProductionService.queryByBatchNumber(batchNumber);
        if(production.getRemainingCapacity()>splitQuantity  && production.getRemainingActivity()>Double.valueOf(activity)/1000){
            Integer concentration=production.getOralConcentration();
            double constantNum = -0.0864089775561;
            double result =concentration * Math.exp(constantNum * (ChronoUnit.DAYS.between(production.getMeasureTine(), dateTime)));


            String totalVolume=decimalFormat.format(splitQuantity * piece);

            String totalActivity=decimalFormat.format(Double.valueOf(activity)  * piece / 1000);
            List<Integer> listShowIds=new ArrayList<>();
            List<IoralStock> listStocks=ioralStockService.querySelective(1,20,batchNumber,"","desc");

            for(IoralStock stocks:listStocks){
                //设置showId
                Integer i=stocks.getShowId();
                if(!listShowIds.contains(i)){
                    listShowIds.add(i);
                }
            }
           int nextLarger=IorderSpecial.findNextNaturalNumber(listShowIds);

            ioralStock.setShowId(nextLarger);
            ioralStock.setEditPieces(piece);
            ioralStock.setPieces(piece);
            ioralStock.setActivity(Double.valueOf(activity));
            ioralStock.setVolume(String.valueOf(splitQuantity));
            ioralStock.setBatchNumber(batchNumber);
            ioralStock.setUseTime(dateTime);
            ioralStock.setBuildTime(LocalDateTime.now());
            ioralStock.setUserName("备货");
            ioralStock.setDeliveryType(deliveryType);
            ioralStock.setSelected(false);
            ioralStock.setOrderCount(Integer.valueOf(orderCount));
            production.setRemainingActivity(Double.valueOf(decimalFormat.format(production.getRemainingActivity()-Double.valueOf(totalActivity))));
            production.setRemainingCapacity(Double.valueOf(decimalFormat.format(production.getRemainingCapacity()-Double.valueOf(totalVolume))));
            productProductionService.updateById(production);
            adminIorderStockService.create(ioralStock);
            logger.info(ioralStock.toString());
            List<StockProductInfo> list =new ArrayList<>();
            StockProductInfo stockProductInfo=new StockProductInfo();
            Map<String,Object> data=new HashMap<>();
            stockProductInfo.setTotalActivity(String.valueOf(production.getProductActivity()));
            stockProductInfo.setTotalVolume(String.valueOf(production.getProductCapacity()));
            stockProductInfo.setRemainVolume(String.valueOf(production.getRemainingCapacity()));
            stockProductInfo.setRemainActivity(String.valueOf(production.getRemainingActivity()));
            stockProductInfo.setDate(LocalDate.now().toString());
            stockProductInfo.setActualCount(activity);
            stockProductInfo.setVolume(String.valueOf(splitQuantity * piece));
            list.add(stockProductInfo);
            data.put("items",list);
            return ResponseUtil.ok(data);

        }else{
            production.setIsEnd(true);
            return  ResponseUtil.fail(1,"剩余体积（活度不够）");
        }


    }



    /**
     * 器材详情
     *
     * @param id
     * @return
     */
    @RequiresPermissions("admin:iorderStock:read")
    @RequiresPermissionsDesc(menu = { "碘131生产发货管理", "生产列表" }, button = "详情")
    @GetMapping("/detail")
    public Object detail(@NotNull Integer id) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 碘生产管理->详情,请求参数,id:{}", id);
        logger.info("hehehehheheh");
        return adminIorderStockService.detail(id);
    }

 /*   @RequiresPermissions("admin:iorderStock:read")
    @RequiresPermissionsDesc(menu = { "碘131生产发货管理", "生产列表" }, button = "查看产品信息")
    @GetMapping("/info")
    public Object detail(@NotNull Integer id) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 碘生产管理->详情,请求参数,id:{}", batchNumber);
        logger.info("根据产品信息查找产品");
        return adminIorderStockService.detail(id);
    }
*/
    @RequiresPermissions("admin:iorderStock:read")
    @RequiresPermissionsDesc(menu = { "碘131生产发货管理", "生产列表" }, button = "详情")
    @GetMapping("/more")
    public Object detail2(@NotNull Integer id) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 碘生详情,请求参数,id:{}", id);
        logger.info("heheh胜多负少h");
        return adminIorderStockService.detail(id);
    }
    /**
     * 删除生产信息
     *
     * @param iorderStock
     * @return
     */
    @RequiresPermissions("admin:iorderStock:deleteIorderStocks")
    @RequiresPermissionsDesc(menu = { "碘131生产发货管理", "生产列表" }, button = "删除")
    @PostMapping("/deleteIorderStocks")
    public Object delete(@RequestBody IoralStock iorderStock) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 器材管理->器材管理->删除,请求参数:{}", JSONObject.toJSONString(iorderStock));

        return adminIorderStockService.delete(iorderStock);
    }


    @GetMapping("/getOneById")
    public Object getOneById(@RequestParam("id") Integer id) {
        logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 器材管理->器材管理->删除,请求参数:{}", JSONObject.toJSONString(Integer.valueOf(id)));
        IoralStock ioralStock=ioralStockService.findById(id);
        Map<String,Integer> data=new HashMap<>();
        if(ioralStock!=null){
            data.put("piece",ioralStock.getEditPieces());
            return data;
        }else{
            return ResponseUtil.fail(0,"获取备货失败，确认有没有这件备货");
        }

    }




}
